package com.elvin.usinglistview;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.os.Build;

public class MainActivity extends Activity implements OnItemClickListener {
	
	private ListView lv;
	private ArrayAdapter<ListCellData> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//使用系统自带的android.R.layout的风格
		adapter = new ArrayAdapter<ListCellData>(this, android.R.layout.simple_list_item_1);
		//使用自定义的风格
		//adapter = new ArrayAdapter<String>(this, R.layout.list_cell);

		lv = (ListView)findViewById(R.id.listView1);
		
		lv.setAdapter(adapter);
		
		adapter.add(new ListCellData("小明","男",12));
		adapter.add(new ListCellData("小红","女",15));
		
		lv.setOnItemClickListener(this);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub
		ListCellData data = adapter.getItem(position);
		
		Toast.makeText(this, String.format("名字：%s，性别：%s，年龄：%d", data.getUserName(), data.getSex(), data.getAge()), Toast.LENGTH_SHORT).show();
	}


}
